package org.finesys.chat.core.base.service.impl;

import lombok.RequiredArgsConstructor;
import org.finesys.ai.core.chat.ChatCompletionResponse;
import org.finesys.ai.core.completion.CompletionResponse;
import org.finesys.ai.core.embedding.EmbeddingResponse;
import org.finesys.ai.core.image.GenerateImagesResponse;
import org.finesys.chat.core.base.chat.ChatRequest;
import org.finesys.chat.core.base.client.ChatClient;
import org.finesys.chat.core.base.factory.ChatModelFactory;
import org.finesys.chat.core.base.service.ChatService;
import org.reactivestreams.Publisher;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class ChatServiceImpl implements ChatService {

    // 注入模型工厂
    private final ChatModelFactory modelFactory;


    @Override
    public Publisher<CompletionResponse> completion(ChatRequest chatRequest) {
        String modelId = chatRequest.getModelId();
        // 根据模型ID获取对应的ChatClient
        ChatClient chatClient = modelFactory.getChatClient(modelId);
        return chatClient.completion(chatRequest);
    }


    @Override
    public Publisher<ChatCompletionResponse> chatCompletion(ChatRequest chatRequest) {
        String modelId = chatRequest.getModelId();
        // 根据模型ID获取对应的ChatClient
        ChatClient chatClient = modelFactory.getChatClient(modelId);
        return chatClient.chatCompletion(chatRequest);
    }


    @Override
    public Publisher<GenerateImagesResponse> imageGeneration(ChatRequest chatRequest) {
        String modelId = chatRequest.getModelId();
        // 根据模型ID获取对应的ChatClient
        ChatClient chatClient = modelFactory.getChatClient(modelId);
        return chatClient.imageGeneration(chatRequest);
    }


    @Override
    public Publisher<EmbeddingResponse> embedding(ChatRequest chatRequest) {
        String modelId = chatRequest.getModelId();
        // 根据模型ID获取对应的ChatClient
        ChatClient chatClient = modelFactory.getChatClient(modelId);
        return chatClient.embedding(chatRequest);
    }
}
